package com.mall.order.service.impl;

import com.mall.common.response.CommonResponse;
import com.mall.constant.enums.CommonStatus;
import com.mall.constant.strings.SuccessMsg;
import com.mall.entity.bargain.BgOrder;
import com.mall.order.mapper.OrderMapper;
import com.mall.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * 秒杀订单服务impl
 *
 * @author ASUS
 * @date 2021/07/18
 */
@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderMapper orderMapper;


    @Override
    public BgOrder insert(BgOrder bgOrder) {
        orderMapper.insert(bgOrder);
        return bgOrder;
    }

    @Override
    public CommonResponse updateOrderStatus(Long id, String status) {
        BgOrder bgOrder = new BgOrder();
        bgOrder.setId(id);
        bgOrder.setStatus(status);
        bgOrder.setUpdateTime(new Date());
        orderMapper.updateStatusById(bgOrder);
//        BgOrder bgOrderById = orderMapper.findOne(id);
//        TbSeckillItem byId = seckillItemFeign.findById(bgOrderById.getOrderItemId());
//        byId.setSaleNum(byId.getSaleNum()+1);
//        if (byId.getSeckillNum().equals(byId.getSaleNum())){
//            byId.setStatus(OrderStatus.BECAME_NVALID.getCode());
//        }
//        seckillItemFeign.update(byId);
        return new CommonResponse(CommonStatus.VALID.getCode(), SuccessMsg.SUCCESS_CODE_200);
    }

    @Override
    public BgOrder findOne(Long id) {
        return orderMapper.findOne(id);
    }



}
